//
//  SimLoading.m
//  TKnowBox
//
//  Created by LiuXubin on 15/3/21.
//  Copyright (c) 2015年 knowin. All rights reserved.
//

#import "SimLoading.h"
#import "SimDefine.h"

@implementation SimLoading


+ (void)showTips:(NSString *)content
{
    [self showTips:content inView:nil];
}

+ (void)showTips:(NSString *)content inView:(UIView *)view
{
    SimOverlay *overlay = [[SimOverlay alloc] init];
    overlay.overlayBackgroundColor = HEXRGBACOLOR(0x000000, 0.6);
    overlay.overlayFontColor = [UIColor whiteColor];
    overlay.overlayRectSize = CGSizeMake(80, 20);
    overlay.rootView = view;
    overlay.overlayText = content;
    SimOverlayOptions options = SimOverlayOptionOverlayTypeText | SimOverlayOptionAutoHide | SimOverlayOptionOverlaySizeRoundedRect | SimOverlayOptionAllowUserInteraction;
    [overlay analyzeOptions:options image:NO imageArray:NO];
}


+ (void)showLoading:(NSString *)content inView:(UIView *)view
{
    [self showLoading:content interaction:NO inView:view];
}

+ (void)showLoading:(NSString *)content interaction:(BOOL)interaction inView:(UIView *)view
{
    SimOverlay *overlay = [[SimOverlay alloc] init];
    overlay.overlayBackgroundColor = HEXRGBACOLOR(0x000000, 0.6);
    overlay.overlayFontColor = [UIColor whiteColor];
    overlay.rootView = view;
    overlay.overlayText = content;
    SimOverlayOptions options = SimOverlayOptionOverlaySizeRoundedRect;
    if (interaction) {
        options |= SimOverlayOptionAllowUserInteraction;
    }
    [overlay analyzeOptions:options image:NO imageArray:NO];
    
}

#pragma mark - Ani Loading
+ (void)showOverlayLoadingInView:(UIView *)view
{
    SimOverlay *overlay = [[SimOverlay alloc] init];
    overlay.backgroundColor = HEXRGBACOLOR(0x000000, 0.3);
    overlay.overlayBackgroundColor = [UIColor clearColor];
    overlay.rootView = view;
    overlay.customAnimationDuration = 0.8;
    overlay.iconSize = CGSizeMake(60, 60);
    overlay.overlayText = nil;
    overlay.showDuration = 0.0f;
    overlay.imageArray = @[SimUIImageNamed(@"overlayLoading01"),
                           SimUIImageNamed(@"overlayLoading02"),
                           SimUIImageNamed(@"overlayLoading03"),
                           SimUIImageNamed(@"overlayLoading04"),
                           SimUIImageNamed(@"overlayLoading05"),
                           SimUIImageNamed(@"overlayLoading06"),
                           SimUIImageNamed(@"overlayLoading07"),
                           SimUIImageNamed(@"overlayLoading08"),];
    SimOverlayOptions options = SimOverlayOptionOverlaySizeRoundedRect;
    [overlay analyzeOptions:options image:NO imageArray:YES];
}

+ (void)showEmptyLoadingInView:(UIView *)view
{
    SimOverlay *overlay = [[SimOverlay alloc] init];
    overlay.overlayBackgroundColor = [UIColor clearColor];
    overlay.rootView = view;
    overlay.customAnimationDuration = 0.8;
    overlay.iconSize = CGSizeMake(53, 55);
    overlay.overlayRectSize = CGSizeMake(150, 150);
    overlay.overlayText = nil;
    
    overlay.imageArray = @[SimUIImageNamed(@"loading_00000"),
                           SimUIImageNamed(@"loading_00001"),
                           SimUIImageNamed(@"loading_00002"),
                           SimUIImageNamed(@"loading_00003"),
                           SimUIImageNamed(@"loading_00004"),
                           SimUIImageNamed(@"loading_00005"),
                           SimUIImageNamed(@"loading_00006"),
                           SimUIImageNamed(@"loading_00007")];
    
    SimOverlayOptions options = SimOverlayOptionOverlaySizeRoundedRect | SimOverlayOptionAllowUserInteraction;
    [overlay analyzeOptions:options image:NO imageArray:YES];
}

#pragma mark - Type Loading
+ (void)showLoadingType:(LoadindType)type content:(NSString *)content
{
    
    UIImage *image = nil;
    switch (type) {
        case LT_Success:
            image = SimUIImageNamed(@"icon_loading_success");
            break;
        case LT_Error:
            image = SimUIImageNamed(@"icon_loading_error");
            break;
        case LT_Warning:
            image = SimUIImageNamed(@"icon_loading_warning");
            break;
        default:
            break;
    }
    
    if (image) {
        SimOverlay *overlay = [[SimOverlay alloc] init];
        overlay.overlayBackgroundColor = HEXRGBACOLOR(0x000000, 0.6);
        overlay.overlayFontColor = [UIColor whiteColor];
        overlay.iconSize = CGSizeMake(27, 27);
        overlay.rootView = nil;
        overlay.overlayText = content;
        overlay.iconImage = image;
        SimOverlayOptions options = SimOverlayOptionOverlaySizeRoundedRect | SimOverlayOptionAutoHide;
        [overlay analyzeOptions:options image:YES imageArray:NO];
    }
    else{
        [self showTips:content];
    }

}

+ (SimOverlay *)showLoading:(NSString *)content progress:(CGFloat)progress
{
    return [self showLoading:content progress:progress interaction:NO inView:nil];
}

+ (SimOverlay * )showLoading:(NSString *)content progress:(CGFloat)progress interaction:(BOOL)interaction inView:(UIView *)view;
{
    SimOverlay *overlay = [[SimOverlay alloc] init];
    overlay.overlayBackgroundColor = HEXRGBACOLOR(0x000000, 0.6);
    overlay.overlayFontColor = [UIColor whiteColor];
    overlay.rootView = view;
    overlay.iconSize = CGSizeMake(40, 40);
    overlay.overlayText = content;
    overlay.showDuration = 0;
    SimOverlayOptions options = SimOverlayOptionOverlaySizeRoundedRect | SimOverlayOptionOverlayTypeProgress;
    if (interaction) {
        options |= SimOverlayOptionAllowUserInteraction;
    }
    [overlay analyzeOptions:options image:NO imageArray:NO];
    overlay.overlayProgress = progress;
    return overlay;
}

+ (void)dismissInView:(UIView *)view
{
    [self dismissInView:view includeSubview:YES];
}

+ (void)dismissInView:(UIView *)view includeSubview:(BOOL)includeSubview
{
    [SimOverlay hideOverlayInView:view includeSubview:includeSubview];
}

@end
